import java.util.Arrays;

public class Array {

    public static void main(String[] args) {
        int[]arr1={2,98,56,80,33,11,2,5};
        int []arr={8,0,9,4,2,5};
        //bubbleSort(arr);  //冒泡排序
        reverse(arr);   //数组逆序
        System.out.println(Arrays.toString(arr));
    }

    //数组逆序
    public static void reverse(int[]arr){
        int i=0,j=arr.length-1;
        while(i<j){
            int tem=arr[i];
            arr[i]=arr[j];
            arr[j]=tem;
            i++;
            j--;
        }
    }
    //冒泡排序
    public static void bubbleSort(int[]arr){
        int tem=0;
        int i=0,j=0;
        for(i=0;i<arr.length-1;i++){    //比较五个数
            for(j=i+1;j<arr.length;j++){  //每个数比较的次数
                if(arr[j]<arr[i]){
                    tem=arr[i];
                    arr[i]=arr[j];
                    arr[j]=tem;
                }
            }
        }
    }

    //二分查找
    public static void main1(String[] args) {
        int[] arr={1,3,4,6,8,11,34,66,80,89};
        int aim=7;
        System.out.println(binarySearch(arr,aim));
    }
    public static int binarySearch(int[]arr,int aim) {
        int left = 0, right = arr.length - 1;
        while (left<=right) {
            int mid = (left + right) / 2;
            if (arr[mid] < aim) {
                left = mid+1;
            } else if (arr[mid]>aim) {
                right=mid-1;
            }else{
                return mid;
            }
        }
        return -1;  //找不到的情况下
    }
}
